package com.orange.controller;


import com.orange.commons.Result;
import com.orange.domain.StatBean;
import com.orange.dto.StatDto;
import com.orange.service.VisitLogService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Emp
 * @projectName: crm
 * @package: com.powernode.controller
 * @className: StatVisitLogController
 * @description: TODO
 * @date: 2021/12/2 17:56
 * @version: 1.0
 */
@RequestMapping("stat")
@RestController
public class StatVisitLogController {

    @Resource
    private VisitLogService visitLogService;

    @GetMapping("statVisitCount.do")
    public Result statVisitCount(StatDto statDto){
        try {
            List<StatBean> list = visitLogService.statVisitCount(statDto);
            List<String> names = new ArrayList<>();
            List<Integer> values = new ArrayList<>();
            for (StatBean statBean : list) {
                names.add(statBean.getName());
                values.add(statBean.getValue());
            }
            Map<String, Object> dataMap = new HashMap<>(16);
            dataMap.put("name",names);
            dataMap.put("value",values);
            return new Result(0,"查询成功",0L,dataMap);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(-1,"查询失败");
        }
    }
}
